package com.chinasofti.filter;

import com.chinasofti.service.EmployeeService;
import com.chinasofti.vo.Employee;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;


public class LoginFilter implements Filter {
    private int start;
    private int end;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //获取session
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpSession session = request.getSession();
//        String empname = (String) session.getAttribute("empname");

        EmployeeService service = new EmployeeService();
        Employee e = service.getLoginsemployee();
        if (e == null){
            request.setAttribute("msg","请先登录");
            request.getRequestDispatcher("login.jsp").forward(servletRequest,servletResponse);
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }


    @Override
    public void destroy() {

    }
}
